<style>
  .el-range-editor.el-input__inner{
    width: 100%;
  }
  .el-button--primary{
    min-width: 90px;
    height: 40px;
    line-height: 30px;
    padding: 0 10px;
  }
  .el-input--suffix .el-input__inner{
    min-width: 110px;
    height: 40px;
    line-height: 30px;
    padding: 0 10px;
    background: #fafafa;
    border-color: #e5e5e5
  }
  .el-select .el-input .el-select__caret{
    display: none;
  }
  .el-input__inner::-webkit-input-placeholder{
    color: #666666 !important;
  }
  .el-pagination{
    margin-top: 4px;
  }
  .el-pagination .number,.el-pagination .btn-prev,.el-pagination .btn-next{
    border: 1px solid #e5e5e5;
    padding: 0;
  }
  .el-pagination button, .el-pagination span:not([class*=suffix]){
    min-width: 50px;
  }
  .el-pagination.is-background .btn-next, .el-pagination.is-background .btn-prev, .el-pagination.is-background .el-pager li{
    margin: 0;
    background: #fff;
    min-width: 40px;
    border-right: 1px solid #e5e5e5;
  }
  #choosePeo{
    height: 40px;
    background: #fff;
  }
</style>
<template>
    <div class="aq_main">
      <div class="aq_content">
        <!-- 筛选条件 -->
        <div class="aqc_screen">
          <div class="scr_input">
            <div class="scr_left">
              <span class="scri_title">模糊搜索：</span>
              <div class="scri_inp">
                <el-input v-model="input" placeholder="请输入搜索关键词"></el-input>
              </div>
              <el-button type="primary" class="screenButton" style="height: 40px" @click="searchList">搜索</el-button>
              <el-button @click="resetClick">重置</el-button>
            </div>
            <div class="scr_right" @click="openScreenClick"><span v-html="openScreen?'收起':'展开'"></span><i :class="openScreen?'el-icon-arrow-down':'el-icon-arrow-up'"></i></div>
          </div>
          <div class="scr_time" v-if="openScreen">
            <div class="scrt_title">搜索时间：</div>
            <div class="chooseTime">
              <el-date-picker
                v-model="chooseTime"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期">
              </el-date-picker>
            </div>
            <div class="choosePeoPle">
              <el-select v-model="choosePeo" placeholder="请选择责任人" id="choosePeo">
                <el-option
                  v-for="item in peoples"
                  :key="item.login"
                  :label="item.firstName"
                  :value="item.login">
                </el-option>
              </el-select>
            </div>
          </div>
        </div>
        <!-- 内容 -->
        <div class="aq_con">
          <div class="aqc_scrs">
            <div class="title">共搜索到 {{searchListsLength}} 条数据</div>
          </div>
          <div class="aqc_buttons">
            <div class="buttons">
              <el-button type="primary" class="buts" @click="createNew"><i class="el-icon-plus"></i> 添加事件</el-button>
              <!-- 所有等级 -->
              <div class="allLevel">
                  <el-dropdown @command="chooseLevel">
                    <el-button type="primary" style="background: #fafafa;border-color: #e5e5e5" :style="{color:levelColor}">
                      {{levelTitle}}<div class="downSJ"></div>
                    </el-button>
                    <el-dropdown-menu slot="dropdown" style="width: 97px">
                      <el-dropdown-item v-for="(item,index) in colorList" :style='{color:item.color}' :command="item" :key="index">{{item.title}}</el-dropdown-item>
                    </el-dropdown-menu>
                  </el-dropdown>
              </div>
              <!-- 所有产品 -->
              <div class="allProduc">
                <i class="jt"></i>
                <el-select v-model="products" placeholder="请选择产品" @change="changeProducts">
                  <el-option
                    v-for="item in productList"
                    :key="item"
                    :label="item"
                    :value="item">
                  </el-option>
                </el-select>
              </div>
              <div class="radios">
                <el-radio v-model="stateRadio" @change="searchList" label="1">已解决</el-radio>
                <el-radio v-model="stateRadio" @change="searchList" label="2">未解决</el-radio>
                <el-radio v-model="stateRadio" @change="searchList" label="3">暂停</el-radio>
              </div>
              <div id="clear" v-if="stateRadio != 0" @click="clearState">清空筛选</div>
            </div>
            <div class="pages" v-if="searchListsLength > 0">
              <el-pagination
                @current-change="pageChange"
                background
                prev-text="上一页"
                next-text="下一页"
                layout="prev, pager, next"
                :current-page="page + 1"
                :page-size="6"
                :total="searchListsLength">
              </el-pagination>
            </div>
          </div>
          <!-- 问题列表 -->
          <div class="conList" v-if="searchListsLength > 0">
            <div class="con" v-for="(item,index) in searchLists">
              <div class="title">
                <div class="title_l" @click="goDetails(item)">
                  <div class="con_name">
                    <span class="conName" v-if="item.baseDoc.data.title != undefined && item.baseDoc.data.title != null && item.baseDoc.data.title != ''">
                      <span class="name">{{item.baseDoc.data.title}}</span>
                    </span>
                    <span class="conName" v-else>
                      <span class="name">{{item.baseDoc.data.product}}</span>
                      <span class="tag">{{item.baseDoc.data.category}}</span>
                    </span>
                    <span class="status" style="color:#3572bd" v-if="item.baseDoc.data.status=='open'">解决中</span>
                    <span class="status" style="color:#999999" v-if="item.baseDoc.data.status=='close'">已解决</span>
                    <span class="status" style="color:#3572bd" v-if="item.baseDoc.data.status=='dstop'">暂停</span>
                  </div>
                </div>
                <div class="title_r">
                  <div class="buttons">
                    <div class="butCon" v-if="item.baseDoc.data.status=='close'">
                      <div class="but butColor1" @click="upstateStatus(item.id,'open')">开启</div>
                    </div>
                    <div class="butCon" v-if="item.baseDoc.data.status=='open'">
                      <div class="but butColor1" @click="upstateStatus(item.id,'dstop')">暂停</div>
                      <div class="but butColor2" @click="upstateStatus(item.id,'close')">关闭</div>
                    </div>
                    <div class="butCon" v-if="item.baseDoc.data.status=='dstop'">
                      <div class="but butColor1" @click="upstateStatus(item.id,'open')">开启</div>
                      <div class="but butColor2" @click="upstateStatus(item.id,'close')">关闭</div>
                    </div>
                  </div>
                </div>
              </div>
              <div @click="goDetails(item)" class="labels">
                <div class="label label1" v-if="item.baseDoc.data.level == 1">红色</div>
                <div class="label label2" v-if="item.baseDoc.data.level  == 2">橙色</div>
                <div class="label label3" v-if="item.baseDoc.data.level  == 3">黄色</div>
                <div class="label label4" v-if="item.baseDoc.data.level  == 4">蓝色</div>
                <div class="label label5" v-if="item.baseDoc.data.target!=undefined && item.baseDoc.data.target!=''">{{item.baseDoc.data.target}}</div>
                <div class="label label6"v-if="item.baseDoc.data.categoryOne!=undefined && item.baseDoc.data.categoryOne!=''">{{item.baseDoc.data.categoryOne}}</div>
              </div>
              <div @click="goDetails(item)" class="introduction">最新时间: {{timestampToTime(item.baseDoc.updateTime)}}　负责人: {{item.baseDoc.creator}}</div>
              <div @click="goDetails(item)" class="describe">
                <span class="des_name">问题描述</span>
                <div class="des_content" v-html="item.baseDoc.data.desc"></div>
              </div>
              <div @click="goDetails(item)" class="ed">
                <div class="ed_left" v-if="item.baseDoc.data.edReport !=undefined">8D：{{item.baseDoc.data.edReport.title}}</div>
                <div class="ed_left" v-else>8D：未启用</div>
                <div class="ed_right" v-if="item.eightD_type != null && item.eightD_type != undefined">
                  <span class="edr_text">D{{item.eightD_type}}</span>
                  <i class="el-icon-arrow-right"></i>
                </div>
              </div>
            </div>
          </div>
          <div class="conList conList_none" v-else>
            <div class="cn_con">
              <div class="cnc_img"><img src="../../../assets/imgs/nullIcon.png"/></div>
              <div class="cnc_span">暂无数据</div>
            </div>
          </div>
        </div>
        <createQuestion v-if="createQuestionOpen" @params="params"></createQuestion>
      </div>
    </div>
</template>

<script>
  import qs from 'qs'
  import {mapState,mapActions,mapGetters} from 'vuex'
  import createQuestion from '../../dialog/createQuestion'
  export default {
    name: "allQuestionIndex",
    data() {
      return {
        imgUrl: localStorage.getItem('imgUrl'),
        openScreen:true,
        input:'',
        chooseTime: '',
        peoples: [],
        choosePeo: '',
        colorList:[
          {title:'所有等级',color:'#666666',level:''},
          {title:'红色',color:'#dc4444',level:'1'},
          {title:'橙色',color:'#ff8c1b',level:'2'},
          {title:'黄色',color:'#ffcd34',level:'3'},
          {title:'蓝色',color:'#3384dd',level:'4'}
        ],
        levelTitle:'请选择等级',
        levelColor:'#666666',
        level: '',
        products:'',
        stateRadio: '0',
        page: 0,
        pageSize:6,
        searchLists:[],
        searchListsLength:0,
      }
    },
    components:{
      createQuestion
    },
    computed:{
      ...mapGetters([
        'createQuestionOpen',
        'productList'
      ])
    },
    created() {
      let self = this
      //获取责任人
      self.$http.get(self.conURL + 'api/users').then(res => {
        self.peoples = res.data
        self.peoples.unshift({firstName:'所有责任人',login:''})
      })
    },
    mounted() {
      let self = this
      self.searchList()
    },
    methods: {
      ...mapActions([
        'upstate'
      ]),
      //展开或者收起
      openScreenClick(){
        let self = this
        self.openScreen = !self.openScreen
      },
      //选择等级
      chooseLevel(command){
        let self = this
        self.levelTitle = command.title
        self.levelColor = command.color
        self.level = command.level
        self.searchList()
      },
      //选择产品
      changeProducts(){
        let self = this
        self.searchList()
      },
      //清空筛选
      clearState(){
        let self = this
        self.stateRadio = 0
        self.searchList()
      },
      //分页
      pageChange(val) {
        let self = this
        self.page = val - 1
        self.searchList()
      },
      //查询列表
      searchList(){
        let self = this
        let key = self.input //关键字
        let creator = self.choosePeo //负责人
        let level = self.level //等级
        let product = self.products == '所有产品'?'':self.products //产品
        let status = '' //筛选按钮
        switch (self.stateRadio) {
          case '1':
            status = 'close'
            break
          case '2':
            status = 'open'
            break
          case '3':
            status = 'dstop'
            break
        }
        let param = {
          page: self.page,
          size: self.pageSize,
          type: 'proposal',
          struct: 'proposal',
        }
        if (self.chooseTime != '' && self.chooseTime != null){ //开始/结束时间
          param['begin'] = self.chooseTime[0].getTime()/1000
          param['end'] = self.chooseTime[1].getTime()/1000
        }
        if (key != '' && key != null){
          param['key'] = key
        }
        if (creator != '' && creator != null){
          param['creator'] = creator
        }
        if (level != '' && level != null && level != 0){
          param['level'] = level
        }
        if (product != '' && product != null){
          param['product'] = product
        }
        if (status != '' && status != null){
          param['status'] = status
        }
        self.$http.get(self.conURL + 'mongo/api/search?' + qs.stringify(param) + '').then(res => {
          self.searchLists = res.data.content
          self.searchListsLength = res.data.totalElements
        })
      },
      //时间戳转换成时间
      timestampToTime(timestamp) {
        var date = new Date(timestamp * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
        var Y = date.getFullYear() + '-';
        var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
        var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
        return Y + M + D;
      },
      //创建新的事件
      createNew(){
        let self = this
        self.upstate({key:'createQuestionOpen',val:true})
      },
      //创建事件弹窗的返回值
      params(params){
        let self = this
        this.$router.push({
          path:'/index/questionContent',
          query:params
        })
      },
      //前往详情
      goDetails(obj){
        this.$router.push({
          path:'/index/questionContent',
          query:obj
        })
      },
      //开启、暂停、关闭
      upstateStatus(id,status){
        let self = this
        let params={
          id:id,
          status:status,
        }
        self.$http.get(self.conURL + 'mongo/api/docs/proposal/status/update?' + qs.stringify(params)).then(res => {
          self.searchList()
        })
      },
      //重置
      resetClick(){
        let self = this
        self.chooseTime = []
        self.input = ''
        self.choosePeo = ''
        self.searchList()
      }
    },
  }
</script>

<style lang="less">
  .aq_main{
    width: 100%;
    height: 100%;
    padding: 43px 62px;
    padding-bottom: 0;
    box-sizing: border-box;
    .aq_content{
      width: 100%;
      height: 100%;
      background: #fff;
      border: 1px solid #e5e5e5;
      border-radius: 5px;
      /* 筛选条件 */
      .aqc_screen{
        display: flex;
        flex-direction: column;
        padding: 30px 23px;
        box-sizing: border-box;
        width: 100%;
        border-bottom: 1px solid #e5e5e5;
        .scr_input{
          display: flex;
          flex-direction: row;
          justify-content: space-between;
          height: 40px;
          .scr_left{
            width: calc(100% - 60px);
            display: flex;
            flex-direction: row;
            .scri_title{
              font-size: 14px;
              color: #666666;
              line-height: 40px;
              margin-right: 12px;
            }
            .scri_inp{
              width: 52.46%;
              margin-right: 20px;
            }
            .screenButton{
              margin-right: 10px;
            }
          }
          .scr_right{
            font-size: 16px;
            color: #0f76c8;
            line-height: 30px;
            cursor: pointer;
            span{
              margin-right: 10px;
            }
          }
        }
        .scr_time{
          margin-top: 15px;
          width: 100%;
          height: 40px;
          display: flex;
          flex-direction: row;
          .scrt_title{
            font-size: 14px;
            color: #666666;
            line-height: 40px;
            margin-right: 12px;
          }
          .chooseTime{
            width: 29.18%;
            margin-right: 20px;
          }
          .choosePeoPle{
            width: 20%;
          }
        }
      }
      /* 内容 */
      .aq_con{
        display: flex;
        flex-direction: column;
        .aqc_scrs{
          display: flex;
          flex-direction: column;
          padding-left: 23px;
          box-sizing: border-box;
          .title{
            font-size: 16px;
            color: #0f76c8;
            width: 100%;
            height: 55px;
            line-height: 55px;
          }
        }
        .aqc_buttons{
          display: flex;
          flex-direction: row;
          justify-content: space-between;
          flex-wrap: wrap;
          padding: 0 23px;
          padding-bottom: 30px;
          box-sizing: border-box;
          .buttons{
            display: flex;
            flex-direction: row;
            .buts{
                margin-right: 10px;
          }
            .allLevel{
              height: 40px;
              margin-right: 10px;
              .downSJ{
                display: inline-block;
                width:0;
                height:0;
                border-left:5px solid transparent;
                border-right:5px solid transparent;
                border-top:7px solid #aaaaaa;
                margin-top: auto;
                margin-bottom: auto;
                margin-left: 9px;
              }
            }
            .allProduc{
              width: 110px;
              height: 40px;
              position: relative;
              margin-right: 30px;
              .jt{
                width:0;
                height:0;
                border-left:5px solid transparent;
                border-right:5px solid transparent;
                border-top:7px solid #aaaaaa;
                position: absolute;
                right: 10px;
                top: 18px;
                z-index: 1;
              }
              .el-input__inner{
                padding-right: 25px !important;
              }
            }
            .radios{
              display: flex;
              flex-direction: row;
              label{
                margin-top: auto;
                margin-bottom: auto;
              }
            }
            #clear{
              height: 40px;
              line-height: 40px;
              text-align: center;
              background: #fafafa;
              color: #666666;
              font-size: 14px;
              margin-left: 15px;
              padding: 0 10px;
              cursor: pointer;
              border: 1px solid #e5e5e5;
              border-radius: 5px;
            }
          }
        }
        /* 问题列表 */
        .conList{
          width: 100%;
          display: flex;
          flex-direction: row;
          flex-wrap: wrap;
          padding: 0 23px;
          padding-bottom: 30px;
          box-sizing: border-box;
          background: #fff;
          .con{
            width: 31%;
            height: 301px;
            border: 1px solid #eeeeee;
            border-radius: 5px;
            margin-right: 2%;
            margin-top: 20px;
            cursor: pointer;
            padding-top: 24px;
            box-sizing: border-box;
            display: flex;
            flex-direction: column;
            box-shadow: #f8f8f9 0px 0px 15px;
            .title{
              width: 100%;
              display: flex;
              flex-direction: row;
              justify-content: space-between;
              margin-bottom: 7px;
              padding: 0 17px;
              box-sizing: border-box;
              .title_l{
                display: flex;
                flex-direction: row;
                width: 75%;
                .con_name{
                  display: flex;
                  flex-direction: row;
                  width: 100%;
                  .conName{
                    max-width: 85%;
                    overflow: hidden;
                    text-overflow:ellipsis;
                    white-space: nowrap;
                    .name{
                      font-size: 20px;
                      line-height: 20px;
                      color: #222222;
                      margin-right: 15px;
                    }
                    .tag{
                      font-size: 18px;
                      line-height: 20px;
                      color: #222222;
                      margin-right: 10px;
                    }
                  }
                  .status{
                    font-size: 14px;
                    line-height: 21px;
                  }
                }
              }
              .title_r{
                .buttons{
                  display: flex;
                  flex-direction: row;
                  .butCon{
                    display: flex;
                    flex-direction: row;
                    .but{
                      width: 42px;
                      height: 24px;
                      text-align: center;
                      line-height: 24px;
                    }
                    .butColor1{
                      border: 1px solid #3572bd;
                      color: #3572bd;
                    }
                    .butColor2{
                      border: 1px solid #dc4444;
                      color: #dc4444;
                      margin-left: 8px;
                    }
                  }
                }
              }
            }
            .labels{
              display: flex;
              flex-direction: row;
              padding: 0 17px;
              box-sizing: border-box;
              .label{
                height: 16px;
                line-height: 16px;
                text-align: center;
                padding: 2px 5px;
                color: #fff;
                border-radius: 2px;
                margin-right: 6px;
                font-size: 12px;
              }
              .label:last-child{
                margin-right: 0;
              }
              .label1{
                background: #dc4444;
              }
              .label2{
                background: #ff8c1b;
              }
              .label3{
                background: #ffcd34;
              }
              .label4{
                background: #3384dd;
              }
              .label5{
                background: #3384dd;
              }
              .label6{
                background: rgb(168, 168, 168);
              }
            }
            .introduction{
              font-size: 14px;
              color: #666666;
              line-height: 14px;
              margin-top: 12px;
              max-width: 100%;
              overflow: hidden;
              text-overflow:ellipsis;
              white-space: nowrap;
              border-bottom: 1px dashed #e5e5e5;
              padding: 0 17px;
              padding-bottom: 12px;
              box-sizing: border-box;
            }
            .describe{
              display: flex;
              flex-direction: column;
              padding: 13px 17px;
              box-sizing: border-box;
              height: 145px;
              .des_name{
                font-size: 14px;
                color: #222222;
                line-height: 14px;
                margin-bottom: 13px;
              }
              .des_content{
                font-size: 14px;
                color: #666666;
                margin-bottom: 13px;
                overflow: hidden;
                img{
                  width: 3.75em;
                  height: 3.75em;
                }
                a{
                  width: 3.75em;
                  height: 3.75em;
                  img{
                    width: 100%;
                    height: 100%;
                  }
                }
              }
            }
            .ed{
              border-top: 1px solid #eeeeee;
              width: 100%;
              height: 42px;
              background: #fafafa;
              display: flex;
              flex-direction: row;
              justify-content: space-between;
              padding: 0 17px;
              box-sizing: border-box;
              .ed_left{
                font-size: 14px;
                color: #666666;
                line-height: 42px;
                max-width: 70%;
                overflow: hidden;
                text-overflow:ellipsis;
                white-space: nowrap;
              }
              .ed_right{
                display: flex;
                flex-direction: row;
                font-size: 18px;
                line-height: 42px;
                .edr_text{
                  color: #3572bd;
                }
                i{
                  margin: auto 0;
                  color: #999999;
                }
              }
            }
          }
          .con:nth-child(1),.con:nth-child(2),.con:nth-child(3){
            margin-top: 0;
          }
        }
        .conList_none{
          padding-top: 165px;
          box-sizing: border-box;
          display: flex;
          flex-direction: column;
          justify-content: center;
          .cn_con{
            display: flex;
            flex-direction: column;
            margin: auto;
            .cnc_img{
              width: 68px;
              height: 68px;
              margin-left: auto;
              margin-right: auto;
              margin-bottom: 28px;
              img{
                width: 100%;
                height: 100%;
              }
            }
            .cnc_span{
              font-size: 22px;
              color: #cccccc;
              text-align: center;
            }
          }
        }
      }
    }
  }
</style>
